import utime
from IR import IRTransmitter
from AcStatus import AcStatus


class AcController:
    """空调红外协议控制器"""

    def __init__(self, pin=15):
        """
        初始化
        :param pin: GPIO引脚编号
        """
        self.pin = pin
        self.ac_status = AcStatus()

        # 常量定义 (时间单位为微秒)
        self.head_mark = 9000  # 起始信号高电平时长
        self.head_space = 4500  # 起始信号低电平时长
        self.bit_mark = 620  # 数据位高电平时长
        self.one_space = 1600  # 数据位1低电平时长
        self.zero_space = 540  # 数据位0低电平时长
        self.footer_space = 19980  # 消息结束间隔

        self.ir_transmitter = self.init_ir()

    def init_ir(self):
        return IRTransmitter(
            bit_mark=self.bit_mark,
            bit1_space=self.one_space,
            bit0_space=self.zero_space,
            pin=self.pin
        )

    def send(self):
        """发送当前状态的红外信号"""
        pass

    def generate_ir_data(self):
        pass
